from flask import Flask,render_template
from datetime import datetime
app = Flask(__name__)

# 把时间格式化定为过滤器
def datetime_format(value, format="%Y年-%m月-%d日 %H:%M"):
    return value.strftime(format)

# 取名为dformat
app.add_template_filter(datetime_format,"dformat")

class User:
    def __init__(self,username, email):
        self.username = username
        self.email = email


@app.route('/')
def hello_world():  # put application's code here
    user = User(username="知了", email="xxx@qq.com")
    person = {
        "username": "张三",
        "email": "zhangsan@qq.com"
    }
    return render_template("index.html", user=user, person=person)
#
# @app.route("/blog/<blog_id>")
# def blog_detail(blog_id):  # put application's code here
#     return render_template("blog_detail.html", blog_id=blog_id, username="知了")
#


# @app.route("/filter")
# def filter_demo():
#     user = User(username="知了xxxx", email="xxx@qq.com")
#     mytime = datetime.now()
#     return render_template("filter.html", user=user, mytime=mytime)

@app.route("/control")
def control_statement():
    age=18
    books = [{
        "name": "三国演义",
        "author": "罗贯中"
    },{
        "name": "三国演义",
        "author": "罗贯中"
    },]
    return render_template("control.html", age=age, books=books)

@app.route("/child1")
def child1():
    return render_template("child1.html")

@app.route("/child2")
def child2():
    return render_template("child2.html")

@app.route('/static')
def static_demo():
    return render_template("static.html")

if __name__ == '__main__':
    app.run()
